package cn.wit.summit.chwan.ui.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.wit.summit.chwan.R;
import cn.wit.summit.chwan.adapters.FragmentPagerAdapter;
import cn.wit.summit.chwan.models.dto.SurplusNumberBean;
import cn.wit.summit.chwan.ui.base.MyActivity;
import cn.wit.summit.chwan.ui.fragment.NoticeCommentFragment;
import cn.wit.summit.chwan.ui.fragment.NoticeMessageFragment;
import cn.wit.summit.chwan.widgets.MessageDialog;
import q.rorbin.badgeview.Badge;
import q.rorbin.badgeview.QBadgeView;

/**
 * Created by pengsk on 2018/4/19.
 */

public class NoticeActivity extends MyActivity {

    @Bind(R.id.tabs)
    SlidingTabLayout tabs;
    @Bind(R.id.viewPager)
    ViewPager viewPager;
    @Bind(R.id.round)
    TextView round;
    Badge messagebadge;

    public SurplusNumberBean surplusNumberBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_download_center);
        ButterKnife.bind(this);
        surplusNumberBean = (SurplusNumberBean) getIntent().getSerializableExtra("numberData");
        setBarTitleTx("消息");
        List<FragmentPagerAdapter.Item> items = new ArrayList<>();
        items.add(new FragmentPagerAdapter.Item("通知", NoticeMessageFragment.newInstance()));
        items.add(new FragmentPagerAdapter.Item("评论", NoticeCommentFragment.newInstance()));
        FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager(), items);
        viewPager.setAdapter(adapter);

        tabs.setViewPager(viewPager);
        if (surplusNumberBean != null) {
            if (surplusNumberBean.getNotice_surplus_number() == 0 && (surplusNumberBean.getReplay_surplus_number() > 0 || surplusNumberBean.getPraise_surplus_number() > 0)) {
                viewPager.setCurrentItem(1);
            } else if (surplusNumberBean.getNotice_surplus_number() > 0 && (surplusNumberBean.getReplay_surplus_number() > 0 || surplusNumberBean.getPraise_surplus_number() > 0)) {
//                //显示红点
//                        .bindTarget(round)
                messagebadge = new QBadgeView(this)
                        .bindTarget(round)
                        .setBadgeNumber(-1)
                        .setBadgeBackgroundColor(Color.RED)
                        .setBadgeTextSize(getResources().getDimensionPixelSize(R.dimen.wdp20), false)
                        .setBadgeGravity(Gravity.END | Gravity.TOP)
                        .setBadgeTextColor(Color.WHITE)
                        .setOnDragStateChangedListener(new Badge.OnDragStateChangedListener() {
                            @Override
                            public void onDragStateChanged(int dragState, Badge badge, View targetView) {
                                if (dragState == 4)
                                    badge.hide(false);
                            }
                        });

            }
        }
        tabs.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                if (position == 1) {
                    if (messagebadge != null)
                        messagebadge.hide(false);
                }
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
